package com.java80.springmall.cloud.zuul.fillter;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

public class TokenFilter extends ZuulFilter {

	@Override
	public Object run() {
		RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletRequest request = ctx.getRequest();
        String id = request.getSession().getId();
        System.out.println("session id="+id);
//        //logger.info("--->>> TokenFilter {},{}", request.getMethod(), request.getRequestURL().toString());
//
//        String token = request.getParameter("token");// 获取请求的参数
//        ctx.setSendZuulResponse(true); //对请求进行路由
//
//        if (StringUtils.isNotBlank(token)) {
//            ctx.setResponseStatusCode(200);
//            ctx.set("isSuccess", true);
//        } else {
//            ctx.setSendZuulResponse(false); //不对其进行路由
//            ctx.setResponseStatusCode(400);
//            ctx.setResponseBody("token is empty");
//            ctx.set("isSuccess", false);
//        }
		return null;
	}

	@Override
	public boolean shouldFilter() {
		return true;
	}

	@Override
	public int filterOrder() {
		return 0;//// filter执行顺序，通过数字指定 ,优先级为0，数字越大，优先级越低
	}

	@Override
	public String filterType() {
		// TODO Auto-generated method stub
		return FilterType.PRE.value;
	}

}
